package com.link2room.blaster.controller.manager;

import com.link2room.blaster.dto.innerUse.InmailBaseDto;
import com.link2room.blaster.facade.IInmailTypeFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.blaster.dto.param.inMail.InmailTypeParamDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/6/28.15:33
 */

@Api(tags = "站内信消息类型")
@RestController
@RequestMapping("/manager/InmaiTypes")
public class InmaiTypeController {

    @Resource
    private IInmailTypeFacadeService iInmailTypeFacadeService;

    @ApiOperation(value = "站内信消息类型创建", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "paramDto", paramType = "body", required = true),
    })
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public BaseResultDto create(@RequestBody InmailTypeParamDto paramDto) throws Exception {
        iInmailTypeFacadeService.createNewInmailType(paramDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "站内信消息类型获取", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto types() throws Exception {
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setListToQueryResult(iInmailTypeFacadeService.typeList(new BaseL2rParamDto()));
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "站内信消息类型详情", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "typeCode", paramType = "path", required = true),
    })
    @RequestMapping(value = "/{typeCode}",method = RequestMethod.GET)
    public BaseResultDto type(@PathVariable("typeCode") String typeCode) throws Exception {
        InmailTypeParamDto paramDto = new InmailTypeParamDto();
        paramDto.setCode(typeCode);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultInfo(iInmailTypeFacadeService.type(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }


    @ApiOperation(value = "站内信消息类型修改", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
    })
    @RequestMapping(method = RequestMethod.PUT)
    public BaseResultDto update(@RequestBody InmailTypeParamDto paramDto) throws Exception {
        iInmailTypeFacadeService.update(paramDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
